<script src="public/js/jquery.webcam.min.js"></script>
<script type="text/javascript" src="public/js/ajaxUploadFile.js"></script>
<form method="post" id="editForm" name="editForm" >
<div id="imgdlg"></div>
<input type="hidden" name="id" value="${(po.id)!}" id="poid">
<input type="hidden" name="pstudent_pic" id="pstudent_pic" value="${(bsp.student_pic)!}">
<input type="hidden" name="pcard_pic" id="pcard_pic" value="${(bsp.id_card_pic)!}">
<input type="hidden" name="pid_card_pic" id="pid_card_pic" value="">
<table class="tableForm tableCss">
    <tr >
        <th style="width:33%;text-align: center">
            身份证头相
        </th>
        <th style="width:33%;text-align: center">
            现场取照
        </th>
        <th style="width:34%;text-align: center">
            实时拍摄
        </th>
    </tr>
    <tr>
        <td align='center'>
            <img src="${(bsp.id_card_pic)!}" id="id_card_pic" name="id_card_pic" >
        </td>
        <td>
            <img src="${(bsp.student_pic)!}" id="student_pic" name="student_pic" style="width:210px">
        </td>
        <td>
            <div id="webcam" style="float: left;"></div>
            
            <div  style="float: right;margin-top: 10px;width: 80px;" >
                <a class="easyui-linkbutton" href="javascript:take_pic();" data-options="iconCls:'icon-save'">拍摄</a>
            
            	<a class="easyui-linkbutton" href="javascript:getcardinfo();" >读身份证</a>
            
            	<a class="easyui-linkbutton" href="javascript:importphoto();" >上传相片</a>

        </td>
    </tr>
</table>
<table class="tableForm tableCss">
    <tr>
        <th style="width: 150px;">学校：</th>
        <td style="width: 40%;">
            <input class="easyui-combotree" style="width: 80%;" name="dep_id" id="dep_id" value="${(po.dep_id!)!}" data-options="url:'admin/department/combotree',method:'get',required:true,onselect:on_change">
        </td>
        <th style="width: 150px;">班级：</th>
        <td>
            <input class="easyui-combobox" style="width: 80%;"  name="class_id" id="class_id" value="${(po.class_id!)!}" data-options="url:'admin/class/load_class_combobox?dep_id=${(po.dep_id!)!}',valueField:'id',textField:'class_name',required:true">
        </td>
    </tr>
    <tr>
        <th>学生名称：</th>
        <td colspan="3">
            <input type="text" style="width: 80%;" class="easyui-textbox" id="student_name_get" name="student_name" value="${(po.student_name!)!}" data-options="required:true">
        </td>
    </tr>
    <tr>
        <th>社保卡号：</th>
        <td>
            <input class="easyui-textbox" style="width: 80%;" type="text" id="student_sb_cart" name="student_sb_cart" value="${(po.student_sb_cart!)!}">
        </td>
        <th>社保卡发放地：</th>
        <td>
            <input class="easyui-textbox" style="width: 80%;" type="text" id="student_sb_ffd" name="student_sb_ffd" value="${(po.student_sb_ffd!)!}">
        </td>
    </tr>
    <tr>
        <th>身份证号：</th>
        <td>
            <input class="easyui-textbox" style="width: 80%;" type="text" id="student_id_cart_get" name="student_id_cart" value="${(po.student_id_cart!)!}" >
        </td>
        <th>性别：</th>
        <td>
            <input class="easyui-combobox" style="width: 80%;" name="student_sex" id="student_sex" value="${(po.student_sex!)!}" data-options="url:'admin/student/sys_pa_code?table=common&field=sex',method:'get',valueField:'id',textField:'name'">
        </td>
    </tr>
    <tr>
        <th>出生日期：</th>
        <td>
            <input class="easyui-datebox" style="width: 80%;" type="text" id="student_birthday" name="student_birthday" value="${(po.student_birthday!)!}" data-options="formatter:myformatter,parser:myparser" >
        </td>
        <th>户籍所在地：</th>
        <td>
            <input class="easyui-combobox" style="width: 80%;" type="text" name="student_hj_address" value="${(po.student_hj_address!)!}" data-options="url:'admin/student/sys_pa_code?table=bk_student&field=student_hj_address',method:'get',valueField:'id',textField:'name'">
        </td>
    </tr>
    <tr>
        <th>户籍地址：</th>
        <td colspan="3">
            <input class="easyui-textbox"  style="width: 80%;" type="text"  id="student_hj_address_detail" name="student_hj_address_detail" value="${(po.student_hj_address_detail!)!}">
        </td>
    </tr>
    <tr>
        <th>户口性质：</th>
        <td>
            <input class="easyui-combobox" style="width: 80%;" name="student_hk_type" id="student_hk_type" value="${(po.student_hk_type!)!}" data-options="url:'admin/student/sys_pa_code?table=bk_student&field=student_hk_type',method:'get',valueField:'id',textField:'name'" >
        </td>
        <th>婚姻状态：</th>
        <td>
            <input class="easyui-combobox" style="width: 80%;" name="student_is_marray" id="student_is_marray" value="${(po.student_is_marray!)!}" data-options="url:'admin/student/sys_pa_code?table=bk_student&field=student_is_marray',method:'get',valueField:'id',textField:'name'">
        </td>
    </tr>
    <tr>
        <th>民簇：</th>
        <td>
            <input class="easyui-combobox" style="width: 80%;" name="student_nationality" id="student_nationality" value="${(po.student_nationality!)!}" data-options="url:'admin/student/sys_pa_code?table=bk_student&field=student_nationality',method:'get',valueField:'id',textField:'name'">
        </td>
        <th>政治面貌：</th>
        <td>
            <input class="easyui-combobox" style="width: 80%;" name="student_political" id="student_political" value="${(po.student_political!)!}"  data-options="url:'admin/student/sys_pa_code?table=bk_student&field=student_political',method:'get',valueField:'id',textField:'name'">
        </td>
    </tr>
    <tr>
        <th>所在单位：</th>
        <td>
            <input class="easyui-textbox" style="width: 80%;" name="at_company" id="at_company" value="${(po.at_company!)!}">
        </td>
        <th>人员类型：</th>
        <td>
            <input class="easyui-combobox" style="width: 80%;" name="student_type" id="student_type" value="${(po.student_type!)!}"   data-options="url:'admin/student/sys_pa_code?table=bk_student&field=student_type',method:'get',valueField:'id',textField:'name'">
        </td>
    </tr>
    <tr>
        <th>鉴定人员类别：</th>
        <td>
            <input class="easyui-combobox" style="width: 80%;" name="app_user_type" id="app_user_type" value="${(po.app_user_type!)!}"  data-options="url:'admin/student/sys_pa_code?table=bk_student&field=app_user_type',method:'get',valueField:'id',textField:'name'">
        </td>
        <th>国家职业资格等级：</th>
        <td>
            <input class="easyui-combobox" style="width: 80%;" name="national_rank" id="national_rank" value="${(po.national_rank!)!}" data-options="url:'admin/student/sys_pa_code?table=bk_student&field=national_rank',method:'get',valueField:'id',textField:'name'">
        </td>
    </tr>
    <tr>
        <th>上一级职业资格级别：</th>
        <td>
            <input class="easyui-combobox" style="width: 80%;" name="up_national_rank" id="up_national_rank" value="${(po.up_national_rank!)!}" data-options="url:'admin/student/sys_pa_code?table=bk_student&field=up_national_rank',method:'get',valueField:'id',textField:'name'">
        </td>
        <th>是否免考理论：</th>
        <td>
            <input class="easyui-combobox" style="width: 80%;" name="is_not_testing_theory" id="is_not_testing_theory" value="${(po.is_not_testing_theory!)!}" data-options="url:'admin/student/sys_pa_code?table=common&field=boolean',method:'get',valueField:'id',textField:'name'">
        </td>
    </tr>
    <tr>
        <th>文化程度：</th>
        <td>
            <input class="easyui-combobox" style="width: 80%;" name="student_cultural" id="student_cultural" value="${(po.student_cultural!)!}" data-options="url:'admin/student/sys_pa_code?table=bk_student&field=student_cultural',method:'get',valueField:'id',textField:'name'">
        </td>
        <th>最高学历专业：</th>
        <td>
            <input class="easyui-textbox" style="width: 80%;" name="student_high_school_record" id="student_high_school_record" value="${(po.student_high_school_record!)!}">
        </td>
    </tr>
    <tr>
        <th>职称：</th>
        <td>
            <input class="easyui-textbox" style="width: 80%;" name="student_title" id="student_title" value="${(po.student_title!)!}">
        </td>
        <th>职务：</th>
        <td>
            <input class="easyui-textbox" style="width: 80%;"  name="student_duty" id="student_duty" value="${(po.student_duty!)!}">
        </td>
    </tr>
    <tr>
        <th>职业年限：</th>
        <td>
            <input class="easyui-textbox" style="width: 80%;" name="student_age_limit" id="student_age_limit" value="${(po.student_age_limit!)!}">
        </td>
        <th>专业技术职务级别：</th>
        <td>
            <input class="easyui-combobox" style="width: 80%;" name="student_duty_rank" id="student_duty_rank" value="${(po.student_duty_rank!)!}" data-options="url:'admin/student/sys_pa_code?table=bk_student&field=student_duty_rank',method:'get',valueField:'id',textField:'name'">
        </td>
    </tr>
    <tr>
        <th>工龄：</th>
        <td>
            <input class="easyui-textbox" style="width: 80%;" name="student_work_age" id="student_work_age" value="${(po.student_work_age!)!}" >
        </td>
        <th>电子邮箱：</th>
        <td>
            <input class="easyui-textbox" style="width: 80%;"  name="student_email" id="student_email" value="${(po.student_email!)!}" >
        </td>
    </tr>
    <tr>
        <th>联系地址：</th>
        <td>
            <input class="easyui-textbox" style="width: 80%;" name="student_address" id="student_address" value="${(po.student_address!)!}">
        </td>
        <th>联系电话：</th>
        <td>
            <input class="easyui-textbox" style="width: 80%;"  name="student_tel_phone" id="student_tel_phone" value="${(po.student_tel_phone!)!}">
        </td>
    </tr>
    <tr>
        <th>基础信息1：</th>
        <td>
            <input class="easyui-textbox" style="width: 80%;" name="student_memo_1" id="student_memo_1" value="${(po.student_memo_1!)!}">
        </td>
        <th>基础信息2：</th>
        <td>
            <input class="easyui-textbox" style="width: 80%;" name="student_memo_2" id="student_memo_2" value="${(po.student_memo_2!)!}">
        </td>
    </tr>
</table>
</form>
<script>

	 var image = new Array();
     var pos = 0;
     var w = 320;
     var h= 240;
     function importphoto(){
     	 $("#imgdlg").dialog({
                title: "上传相片",
                iconCls: 'icon-edit',
                width: 300,
                height: 150,
                closed: false,
                cache: false,
                modal: false,
                href: "admin/student/importphoto",
                onLoad: function () {
                    $.messager.progress('close');
                },
                buttons:[{
                    text: '取消',
                    iconCls:'icon-cancel',
                    handler: function () {
                        $("#imgdlg").dialog("close");
                    }
                },{
                    text: '确定',
                    iconCls: 'icon-ok',
                    handler: function(){
                         $('#import_img_Form').form('submit',{
                            url:"admin/student/importImgStu",
                            dataType:"json",
                            onSubmit:function(){
                                
                            },
                            success:function(data){
                                var data = eval('(' + data + ')');  // change the JSON string to javascript object
                                
                                if(data.success == 1){
							      $("#student_pic").attr("src",data.obj);
					              $("#pstudent_pic").val(data.obj);
					              $("#student_pic").show();
					              $("#imgdlg").dialog("close");
							    } else{
							      alert('上传失败！');
							    }
                            }
                        });
					    
					}
                }]
            });
     }
     $(document).ready(function(){
            $("#webcam").webcam({
                width: 240,
                height: 180,
                mode: "callback",
                swffile: "public/js/jscam_canvas_only.swf", // canvas only doesn't implement a jpeg encoder, so the file is much smaller

                onTick: function(remain) {
                    alert("tick.....");
                },

                onSave: function(data) {

                    var id =  $("#id").val();
                    image.push(data);
                    pos += 4 * w;
                    if (pos == 4 * w * h) {
                        $.ajax({type:"post",
                            url:"admin/student/save_pic",
                            data:{id:id,w: w, h: h , pix:image.join('|')},
                            dataType:"JSON",
                            success:function (data) {
//                                var data = eval('(' + data + ')');  // change the JSON string to javascript object
                                if(data.success==1){
                                    $("#student_pic").attr("src",data.obj);
                                    $("#pstudent_pic").val(data.obj);
                                    $("#student_pic").show();
                                }else{
                                    $("#student_pic").hide();
                                }
                                pos = 0;
                                image = new Array();
                                $.messager.progress('close');

                            }});
                    }

                },

                onCapture: function () {
                    webcam.save();

                    // Show a flash for example
                },

                debug: function (type, string) {
                    // Write debug information to console.log() or a div, ...
                },

                onLoad: function () {

                }
            });


        });
        
    $(function(){
        $("#teacher_id").combogrid({
            panelWidth:450,
            idField:'id',
            textField:'name',
            value:"${(po.teacher_id!)!}",
            url:'admin/user/listTeacherJson',
            columns:[[
                {field:'id',title:'ID',width:60},
                {field:'name',title:'名称',width:100},
                {field:'phone',title:'联系方式',width:120},
                {field:'email',title:'邮箱',width:100}
            ]]
        });
    });

	function ajaxFileUpload(){
		var fileToUpload = $("#fileToUpload").val();
	    if(fileToUpload == null || fileToUpload==""){
	        $.messager.alert("上传出错","请选择图片");
	        return;
	    }
	    
	$.ajaxFileUpload({
		  url:'admin/student/importImgStu',//服务器端程序
		  secureuri:false,
		  fileElementId:'fileToUpload',//input框的ID
		  dataType: 'json',//返回数据类型
		  beforeSend:function(){//上传前需要处理的工作，如显示Loading...
		  },
		  success: function (data, status){//上传成功
		   
		    if(data.success == 1){
		      $("#student_pic").attr("src",data.obj);
                                       $("#pstudent_pic").val(data.obj);
                                   	   $("#student_pic").show();
		    } else{
		      alert('上传失败！');
		    }
		  }
		});

		

	
	}
    function on_change(){
        var dep_id = $("#dep_id").combotree("getValue");
        $("#class_id").combobox("reload",'admin/class/load_class_combobox?dep_id='+dep_id);
    }

    function myformatter(date){
        var y = date.getFullYear();
        var m = date.getMonth()+1;
        var d = date.getDate();
        return y+'-'+(m<10?('0'+m):m)+'-'+(d<10?('0'+d):d);
    }
    function myparser(s){
        if (!s) return new Date();
        var ss = (s.split('-'));
        var y = parseInt(ss[0],10);
        var m = parseInt(ss[1],10);
        var d = parseInt(ss[2],10);
        if (!isNaN(y) && !isNaN(m) && !isNaN(d)){
            return new Date(y,m-1,d);
        } else {
            return new Date();
        }
    }
    
    //身份证信息
        function getcardinfo() {
		   
		   var ret = CVR_IDCard.ReadCard();
		   if (ret == "0"){
		      fillForm();
		      return;
		   } 
		
		   alert("读卡错误,错误原因:" + ret);
		}
		
		function clearForm() {
		  $("#student_name_get").textbox('setValue','');
		  $("#student_sex").textbox('setValue','');
		  $("#student_nationality").textbox('setValue','');
		  $("#student_birthday").datebox('setValue','');
		  $("#student_hj_address").textbox('setValue','');
		  $("#student_id_cart_get").textbox('setValue','');
		  //easyui-datebox
		  $("#student_hj_address_detail").textbox('setValue','');
		  document.all['id_card_pic'].value = ''; 
		}
		function fillForm() {   
		  var pName=CVR_IDCard.Name; 
		  var pSex=CVR_IDCard.Sex;
		  var pNation=CVR_IDCard.Nation;
		  var pBorn=CVR_IDCard.Born;
		  var pAddress=CVR_IDCard.Address;
		  var pCardNo=CVR_IDCard.CardNo;
		  var pPolice=CVR_IDCard.IssuedAt;
		  var pActivityLFrom=CVR_IDCard.EffectedDate; 
		  var pActivityLTo=CVR_IDCard.ExpiredDate; 
		  var pDeviceNo=CVR_IDCard.CardReaderId;
		  var pPhotoBuffer=CVR_IDCard.Picture;  
		  
		  var y = pBorn.substr(0,4);
		  var m = pBorn.substr(4,2);
		  var r = pBorn.substr(6,2);
		  pBorn = y+"-"+m+"-"+r;
		  
		  //alert(pName);
		  //alert(pCardNo);
		  
		
		  $("#student_name_get").textbox('setValue',pName);
		  $("#student_id_cart_get").textbox('setValue',pCardNo);
		  $("#student_sex").combobox('setValue',pSex==1?"9":"8");
		 
		  $("#student_birthday").datebox('setValue',pBorn);
		  $("#student_hj_address").textbox('setValue',pPolice);
		  
		  //$("#s_cid").searchbox('setValue',pCardNo);
		  $("#student_hj_address_detail").textbox('setValue',pAddress);
		  document.all['id_card_pic'].src = 'data:image/jpeg;base64,' + pPhotoBuffer; 
		  $("#pid_card_pic").val(pPhotoBuffer);
		  //$("#student_birthday").datebox('setValue',pBorn);
		  //$("#student_birthday").datebox('setValue', '2014-9-12');
		  
		 
		  
		  
		  $.ajax({type:"post",
                  url:"admin/student/nation",
                  data:{name:pNation},
                  dataType:"JSON",
                  success:function (data) {

                      if(data.success==1){
                          //alert(data.obj);
                          $("#student_nationality").combobox('setValue',data.obj);
                      }else{
                         
                      }

           }});
		  
		  //doSearch(pCardNo);
		}
		function take_pic(){
            $.messager.progress({
                msg:'处理中.....'
            });
            webcam.capture();
        }

</script>
